// 长者管理

import { alovaInstance as alova } from './alova'
import type { ApiCommonResponse } from '@/types'

// 楼栋详情
export function queryBuildDetail(id: number) {
  return alova.Get<ApiCommonResponse>(`/apartment/${id}/assemble`, {
    localCache: void 0,
  })
}
export function queryBuild() {
  return alova.Get<ApiCommonResponse>('/apartment/list', {
    localCache() {
      return void 0
    },
  })
}

export interface AddBuildParam {
  name: string
}

export interface AddFloorParam extends AddBuildParam {
  apartmentID: number
}

export interface AddRoomParam extends AddFloorParam {
  floorID: number
}

export interface AddBedParam extends AddRoomParam {
  roomID: number
}

export interface SaveBuildParam extends AddBuildParam {
  apartmentID: number
}

export interface SaveFloorParam extends AddBuildParam {
  floorID: number
}

export interface SaveRoomParam extends AddBuildParam {
  roomID: number
}

export interface SaveBedParam extends AddBuildParam {
  bedID: number
}

// 增加楼栋
export const addBuild = (data: AddBuildParam) => alova.Post<ApiCommonResponse>('/apartment/add', { ...data })

// 增加楼层
export const addFloor = (data: AddFloorParam) => alova.Post<ApiCommonResponse>('/floor/add', { ...data })

// 增加房间
export const addRoom = (data: AddRoomParam) => alova.Post<ApiCommonResponse>('/room/add', { ...data })

// 增加床位
export const addBed = (data: AddBedParam) => alova.Post<ApiCommonResponse>('/bed/add', { ...data })

// 保存楼栋
export const saveBuild = (data: SaveBuildParam) => alova.Put<ApiCommonResponse>(`/apartment/${data.apartmentID}/save`, { ...data })

// 保存楼层
export const saveFloor = (data: SaveFloorParam) => alova.Put<ApiCommonResponse>(`/floor/${data.floorID}/save`, { ...data })

// 保存房间
export const saveRoom = (data: SaveRoomParam) => alova.Put<ApiCommonResponse>(`/room/${data.roomID}/save`, { ...data })

// 保存床位
export const saveBed = (data: SaveBedParam) => alova.Put<ApiCommonResponse>(`/bed/${data.bedID}/save`, { ...data })
